home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-11 | 1.7 KB | 56 lines | [TEXT/CWIE] |
- // TGmt.cp - G M Time class object
- //
- // Apple Macintosh Developer Technical Support
- // Written by: Vinne Moscaritolo
- //
- // Copyright (work in progress) Apple Computer, Inc All rights reserved.
- //
- // You may incorporate this sample code into your applications without
- // restriction, though the sample code has been provided "AS IS" and the
- // responsibility for its operation is 100% yours. However, what you are
- // not permitted to do is to redistribute the source as "DSC Sample Code"
- // after having made changes. If you're going to re-distribute the source,
- // we require that you make it clear in the source that the code was
- // descended from Apple Sample Code, but that you've made changes.
- //
-
- #include "TGMT.h"
- #include <iomanip.h>
- #include <OSUtils.h>
-
- void TGmt::Now()
- {
- GetDateTime(&fTime);
- };
-
- unsigned long TGmt::Elapsed()
- {
- unsigned long now;
- GetDateTime(&now);
- return (now - fTime);
- };
-
- ostream &operator<< (ostream& s, const TGmt& t)
- {
- const char* wkday[]= {"XXX","Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
- const char* month[] = {"XXX","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
- DateTimeRec d;
- MachineLocation loc;
- long delta;
- long savedflags;
-
- // normalize for GMT
- ReadLocation(&loc);
- delta = 0x00FFFFFF & loc.u.gmtDelta;
- if(delta & 0x00800000) delta |= 0xff000000;
-
- // Convert to Stream
- SecondsToDate(t.fTime - delta ,&d);
- savedflags = s.setf(ios::right, ios::adjustfield);
- s << setfill('0');
- s << wkday[ d.dayOfWeek ] << ", " << setw(2) << d.day << " " << month[d.month] << " " << setw(4) << d.year << " ";
- s << setw(2) << d.hour << ":" << setw(2) << d.minute << ":" << setw(2) << d.second <<" GMT";
- s.setf(savedflags);
- return s;
- };
-